<?php
/**
 * Created by PhpStorm.
 * User: lance
 * Date: 2017/11/1
 * Time: 15:50
 */

namespace app\common\log\addRole;

use app\common\log\Base;
use think\Db;

/**
 * 客户经理,领导添加日志
 * Class CustomerAdd
 * @package app\log\common
 */
class ManagerAdd extends Base
{
    private $i_action;
    const ROLE_TYPE = 2;//添加的角色类型为客户经理

    public function __construct(array $a_data)
    {
        parent::__construct();
        $this->a_data = $a_data;
        //操作角色
        switch ($this->i_role):
            //超级管理员
            case '1':
                $this->i_action = 1;
                break;
            //领导
            case '2':
                $this->i_action = 2;
                break;
        endswitch;
        //更新
        if (isset($a_data['update']) && $a_data['update']):
            if ($this->a_data['role_type'] == 3):
                $this->i_action ++;
            else:
                $this->i_action += 4;
            endif;
        endif;
        //批量导入
        if (isset($a_data['type']) && $a_data['type'] == 2):
            $this->i_action += 2;
        endif;
    }

    public function addOne()
    {
        //角色日志
        $this->a_data = array_merge($this->a_data, $this->commonData());
        $this->a_data = array_merge($this->a_data, [
            'action' => $this->i_action,
            'role_type' => $this->a_data['role_type'] ?: self::ROLE_TYPE,
        ]);
        Db::name('role_log')->insert($this->a_data);

    }
}